//
//  TabBarController.m
//  GymJT
//
//  Created by    🐯 on 16/9/8.
//  Copyright © 2016年 张炫赫. All rights reserved.
//

#import "TabBarController.h"
#import "NavigationViewController.h"




@interface TabBarController ()<UITabBarDelegate,UITabBarControllerDelegate>

@end

@implementation TabBarController

+(void)initialize{
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[self]];

    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
    selectTextAttrs[NSForegroundColorAttributeName] = HexColor(@"00a2ff");
    [item setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
    
    NSMutableDictionary *unSelectTextAttrs = [NSMutableDictionary dictionary];
    unSelectTextAttrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    [item setTitleTextAttributes:unSelectTextAttrs forState:UIControlStateNormal];
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.selectedIndex = 1 ;
    self.delegate = self;
    UIImage *img = [UIImage imageWithColor:HexColor(@"ffffff")];
    self.tabBar.backgroundImage = img;
    [self setUpAllChildViewController];
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    return YES;
}


#pragma mark - 添加所有的子控制器
- (void)setUpAllChildViewController{
    
    UIViewController *one=[[UIViewController alloc]init];
    one.view.backgroundColor = [UIColor redColor];
    [self setupCpint:one title:@"1" imageName:@"nav_home"];

    UIViewController *two=[[UIViewController alloc]init];
    two.view.backgroundColor = [UIColor greenColor];
    [self setupCpint:two title:@"2" imageName:@"nav_goods_class"];
    
    UIViewController *three=[[UIViewController alloc]init];
    three.view.backgroundColor = [UIColor yellowColor];
    [self setupCpint:three title:@"3" imageName:@"nav_my_info"];
    
}

#pragma mark - 添加一个子控制器
-(void)setupCpint:(UIViewController *)contller title:(NSString *)title imageName:(NSString *)imageName{
    contller.title=title;
    
    UIImage *selectedimage = img(string(@"%@",imageName));
    UIImage *unselectedimage = img(string(@"%@_off",imageName));
    
    contller.tabBarItem.image=[unselectedimage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    contller.tabBarItem.selectedImage=[selectedimage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    NavigationViewController *nav=[[NavigationViewController alloc]initWithRootViewController:contller];
    
    [self addChildViewController:nav];
}


@end
